from app import db


class Message(db.Model):
    __tablename__ = 'tbl_message'

    Message_id = db.Column(db.Integer, primary_key=True)
    User_id = db.Column(db.String(10), nullable=False)
    Cos_id = db.Column(db.String(10), nullable=False)
    Message = db.Column(db.String, nullable=False)
    Message_time = db.Column(db.DateTime(), nullable=False)
    Message_send = db.Column(db.SmallInteger, primary_key=True)

    def to_json(self):
        return {
            "Message_id": self.Message_id,
            "User_id": self.User_id,
            "Cos_id": self.Cos_id,
            "Message": self.Message,
            "Message_time": str(self.Message_time),
            "Message_send": self.Message_send
        }
